#include<cstdio>//uncle-lu
#include<cstring>
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

int F[310][310];
int sum[310];
int line[310];
int n;

int main()
{
	read(n);
	for (int i = 1; i <= n; i++) 
	{
		read(line[i]);
		sum[i] = sum[i-1] + line[i]; // 前缀和
	}

	memset(F, 0x7f7f7f, sizeof(F));
	for (int i = 1; i <= n; i++) 
		F[i][i] = 0;

	for (int len = 2; len <= n; len++) //枚举长度
	{
		for (int l = 1; l <= n-len+1; l++) //枚举左端点
		{
			int r = l + len - 1; // 计算出右端点
			for (int k = l; k <= r-1; k++)  // 枚举中间节点
				F[l][r] = std::min(F[l][r], F[l][k] + F[k+1][r]);

			F[l][r] += (sum[r] - sum[l-1]); // 加上区间和
		}
	}

	printf("%d", F[1][n]); // 最终状态

	return 0;
}
